
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.controller' );
require_once(JPATH_COMPONENT.DS.'libraries'.DS.'RestUtils.php');
require_once(JPATH_COMPONENT.DS.'libraries'.DS.'RestRequest.php');

class SocialRoutesControllerRest extends JController{
	
	public function route(){
		$restRequest = RestUtils::processRequest();
		switch($restRequest->getMethod())
		{
			case 'get':
				// delegamos al modelo para que devuelva la lista de eventos
				// nos devuelve una ristra de DTOEvent
				$idUser=JFactory::getUser()->id;;
				if($idUser)
				{
					$modeloRutas= $this->getModel('Route','ModelSocialRoutes');
					//Get the route
					$requestObjet=$restRequest->getRequestVars();
					$id=$requestObjet['id'];
					$dtoRuta=$modeloRutas->readRoute($id);
					//Set the POIs on the route
					$modelPOIs = &$this->getModel( 'poi', 'ModelSocialRoutes' );
					$dtoRuta->setPois($modelPOIs->getRoutePOIs($id));
					//Send the route
					RestUtils::sendResponse(200, json_encode($dtoRuta), 'application/json');
				}
				RestUtils::sendResponse(404);  
				break;
		}
	}
}
